$.ajaxSetup({
	dataType : "json",
	contentType : "application/json",
	cache : false,
// async : false 默认同步加载
// type: "POST" , 默认使用POST方式

});
$(function () {
    $("#jqGrid").jqGrid({
        url: '../hisemployee/list',
        datatype: "json",
        colModel: [			
			{ label: '姓名', name: 'name',frozen : true, width: 80 }, 	
			{ label: '员工编号', name: 'workno',frozen : true, width: 80 },
			{ label: '职位名称', name: 'jobName',frozen : true, width: 80 }, 
			{ label: '部门名称', name: 'deptName',frozen : true, width: 80 },
			{ label: '出生日期', name: 'birthday', width: 100, formatter: function(value, options, row){if(value!=null){return value.substring(0,10)}return ""}}, 			
			{ label: '性别', name: 'gender', width: 80,formatter: function(value, options, row){
				return value === true ? 
						'<span class="label label-primary">男</span>' : 
						'<span class="label label-info">女</span>';
				}}, 		
			{ label: '身份证号', name: 'cardno', width: 160 }, 			
						
			{ label: '上级工号', name: 'upworkno', width: 100,hidden:true }, 			
			{ label: '职位编号', name: 'jobno', width: 80,hidden:true }, 
						
			{ label: '部门编号', name: 'deptno', width: 80,hidden:true },
			
			{ label: 'sys_user的id字段', name: 'userid', width: 80,hidden:true }, 	
			{ label: '用户名称', name: 'userName', width: 80},
			{ label: '入职时间', name: 'inorgtime', width: 100, formatter: function(value, options, row){
				return value.substring(0,10)} }, 			
			{ label: '转正时间', name: 'zztime', width: 100, formatter: function(value, options, row){
				if(value!=null){
					return value.substring(0,10) }
				return ""}}, 			
			{ label: '离职时间', name: 'outorgtime', width: 100, formatter: function(value, options, row){
				if(value!=null){
					return value.substring(0,10)
				}
				return ""} }, 			
				{ label: '是否公司手机', name: 'hasorgmobile', width: 100,formatter: function(value, options, row){
					return value === true ? 
							'<span class="label label-primary">是</span>' : 
							'<span class="label label-info">否</span>';
					} }, 	
			{ label: '手机号码', name: 'mobileno', width: 160 }, 			
			{ label: '推荐人', name: 'recName', width: 80 }, 	
			{ label: '育成人', name: 'bredName', width: 80,hidden:true }, 		
			{ label: '备注', name: 'memo', width: 80 }, 				 			
			{ label: '状态', name: 'state', width: 80,hidden:true, formatter: function(value, options, row){
				return value === 0 ? 
						'<span class="label label-danger">禁用</span>' : 
						'<span class="label label-success">正常</span>';
				} }, 					
        ],
		viewrecords: true,
        height: $(window).height()-120,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        width:window.screen.availWidth-250,  
        autowidth: false,  
        shrinkToFit: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            sort:"sort",//需要排序的列
            order: "order"
        },
        gridComplete:function(){
        	$('.ui-jqgrid-bdiv').scrollTop(0);
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    jQuery("#jqGrid").jqGrid('setFrozenColumns');
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		hisEmployee: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},	
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.hisEmployee = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.hisEmployee.id == null ? "../hisemployee/save" : "../hisemployee/update";
			$.ajax({
				type: "POST",
			    url: url,
			    data: JSON.stringify(vm.hisEmployee),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../hisemployee/delete",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../hisemployee/info/"+id, function(r){
                vm.hisEmployee = r.hisEmployee;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var timedata=$("#inorgtime").val();
			console.log(timedata)
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'time':timedata},			
                page:page
            }).trigger("reloadGrid");
		}
	}
});